#include <head.h>

typedef void*(*fork_k)(void*);//函数指针    

typedef struct str_fork
{
int pid;
int id;
char name[128];
}str_fork;

int fork_fun(fork_k func, void * data)
{
    if (NULL==func)
    {
        return -1;
    }
    int pid=0;
    
    if (-1==(pid=fork()))
    {
        perror("fork error");
       return -1;
    }
    else if (0==pid)
    {
        func(data);

    }
    else if (0<pid)
    {
       return pid;
    }
    return -1;
    
}

void *func_1(void *data)
{
    struct str_fork *p=data;
    printf("child process,id:%d,pid:%d,name:%s\n",p->id,getpid(),p->name);
    exit(0);
}

int main(int argc, char const *argv[])
{
    str_fork S1={.id=0, .name="zhangsan", .pid=getpid()};
    fork_fun(func_1,&S1);
    return 0;
}
